package GroupingComparator;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class OrderGroupingComparator extends WritableComparator {
    public OrderGroupingComparator() {
        super(OrderBean.class, true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {
        OrderBean abean = (OrderBean) a;
        OrderBean bbean = (OrderBean) b;

        int result;
        if (abean.getOrder_id() > bbean.getOrder_id()) {
            result = 1;
        } else if (abean.getOrder_id() < bbean.getOrder_id()) {
            result = -1;
        } else {
            result = abean.getPrice() > bbean.getPrice() ? -1 : 1;
        }
        return result;
    }
}

